import path from 'path'
import { defineConfig,loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { createStyleImportPlugin } from 'vite-plugin-style-import'

// https://vitejs.dev/config/
export default defineConfig(({ command,mode }) => {
  return ({
    base: "/",
    root:process.cwd(),
    define: {
      MENU_PATH: `"path"`,
      MENU_SHOW: `"isShowOnMenu"`,
      MENU_KEEPALIVE: `"keepAlive"`,
      MENU_KEY: `"key"`,
      MENU_ICON: `"icon"`,
      MENU_TITLE: `"label"`,
      MENU_CHILDREN: `"children"`,
      MENU_PARENTKEY: `"parent_id"`,
      MENU_ALLPATH: `"allPath"`,
      MENU_PARENTPATH: `"parentPath"`,
    },
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
      },
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', ".less"]
    },
    plugins: [
      react(),
      createStyleImportPlugin({
        libs: [
          {
            libraryName: 'antd',
            esModule: true,
            resolveStyle: name => `antd/es/${name}/style/index`,
          },
        ],
      }),
    ],
    build: {
      outDir: `cloud_home`,
      minify: process.env.NODE_ENV === 'production' ? 'esbuild' : false,
    },
    css: {
      preprocessorOptions: {
        less: {
          modifyVars: {
            "@primary-color": "#0079FE"
          },
          javascriptEnabled: true,
        },
      },
    },
    server: {
      port: 3000,
      open: true,
      host: true,
      proxy: {
        '^/api': {
          target: 'http://10.176.64.37:5000',
          // target: 'http://cloud.test.net/api',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/api/, '')
        },
      },
    },
    envPrefix:'REACT_APP_'
  })
})

